﻿using LS.Screening.UI.Common;
using LS.Screening.UI.Common.Models;
using ReactiveUI;
using System.Collections.ObjectModel;
using System.Reactive;
using System.Windows;

namespace LS.Screening.UI.Main.ViewModels
{
    public class MainViewModel : ViewModel
    {
        #region 属性

        bool isLeftDrawerOpen = true;
        /// <summary>
        /// 左侧是否展开
        /// </summary>
        public bool IsLeftDrawerOpen { get => isLeftDrawerOpen; set => this.RaiseAndSetIfChanged(ref isLeftDrawerOpen, value); }

        ObservableCollection<MenuItem> menuItemList = new ObservableCollection<MenuItem>();
        /// <summary>
        /// 表单集合
        /// </summary>
        public ObservableCollection<MenuItem> MenuItemList { get => menuItemList; set => this.RaiseAndSetIfChanged(ref menuItemList, value); }

        MenuItem selectedItem;
        /// <summary>
        /// 选中表单
        /// </summary>
        public MenuItem SelectedItem { get => selectedItem; set => this.RaiseAndSetIfChanged(ref selectedItem, value); }

        #endregion

        #region Commands

        /// <summary>
        /// 退出命令
        /// </summary>
        public ReactiveCommand<Unit, Unit> ExitCommand { get; private set; }

        /// <summary>
        /// 重启命令
        /// </summary>
        public ReactiveCommand<Unit, Unit> RestartCommand { get; private set; }

        /// <summary>
        /// 切换到上一个页面
        /// </summary>
        public ReactiveCommand<Unit, Unit> MovePrevCommand { get; private set; }

        /// <summary>
        /// 切换到下一个页面
        /// </summary>
        public ReactiveCommand<Unit, Unit> MoveNextCommand { get; private set; }

        #endregion

        #region 构造

        public MainViewModel()
        {
            this.ExitCommand = ReactiveCommand.Create(() => Exit());
            this.RestartCommand = ReactiveCommand.Create(() => Restart());
            this.MovePrevCommand = ReactiveCommand.Create(MovePrev);
            this.MoveNextCommand = ReactiveCommand.Create(MoveNext);
        }

        #endregion

        #region 方法

        /// <summary>
        /// 初始化方法
        /// </summary>
        /// <returns></returns>
        public override async Task Init()
        {
            await base.Init();
            InitMenus();
        }

        /// <summary>
        /// 初始化菜单
        /// </summary>
        private void InitMenus()
        {
            var homeItem = new MenuItem("系统首页", "LS.Screening.UI.Main.Views", "LS.Screening.UI.Main.Views.HomeView");
            this.MenuItemList.Add(homeItem);

            var registerItem = new MenuItem("筛查管理", "LS.Screening.UI.Register.Views", "LS.Screening.UI.Register.Views.RegisterManageView");
            this.MenuItemList.Add(registerItem);

            var reportItem = new MenuItem("报告管理", "LS.Screening.UI.Report.Views", "LS.Screening.UI.Report.Views.TestView");
            this.MenuItemList.Add(reportItem);
            this.SelectedItem = MenuItemList.FirstOrDefault();
        }

        /// <summary>
        /// 退出方法
        /// </summary>
        private void Exit()
        {
            Application.Current.Shutdown();
        }

        /// <summary>
        /// 重启方法
        /// </summary>
        private void Restart()
        {
            Application.Current.Shutdown();
            System.Windows.Forms.Application.Restart();
        }

        /// <summary>
        /// 切换到上一个
        /// </summary>
        private void MovePrev()
        {

        }

        /// <summary>
        /// 切换到下一个
        /// </summary>
        private void MoveNext()
        {

        }

        #endregion
    }
}
